<template>
    <!-- 图纸目录清单 -->
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
            <div>
                <a-button
                    class="mb12"
                    v-btnPermission="'tm_022_add_01'"
                    type="primary"
                    icon="plus"
                    @click="handleManage(2)"
                    >新增</a-button
                >
            </div>
            <list-table
                ref="table"
                size="default"
                rowKey="key"
                :page-keys="['pageNum', 'pageSize', 'totalSize']"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a v-btnPermission="'tm_022_loo_04'" @click="handleManage(0, record)">查看</a>
                    <!-- 编辑 -->
                    <span
                        v-btnPermission="'tm_022_edi_02'"
                        v-if="record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST'"
                    >
                        <a-divider type="vertical" />
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                    <!-- 删除 -->
                    <span
                        v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'"
                        v-btnPermission="'tm_022_del_03'"
                    >
                        <a-divider type="vertical"></a-divider>
                        <a @click="handleRemoveParams({ id: record.id })">删除</a>
                    </span>

                    <span
                        v-btnPermission="'tm_022_loo_04'"
                        v-if="
                            record.auditStatus === 'PAST' ||
                            record.auditStatus === 'SUBMITTED' ||
                            record.auditStatus === 'REJECTED'
                        "
                    >
                        <a-divider type="vertical" />
                        <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
                    </span>
                        </MoreButton>
                </span>
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                        :isApproval="true"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import BasePage from '@/views/basePage' // 基础配置
import { getPageTechnicalYearlyPlan, delTechnicalYearlyPlan } from '@/api/technical/technicalReview'

import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { status } from '../model.js'
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        }
    },
    {
        title: '年份',
        dataIndex: 'year'
    },
    {
        title: '分公司',
        dataIndex: 'branchComName'
    },
    {
        title: '项目',
        dataIndex: 'projectName'
    },
    {
        title: '填报人',
        dataIndex: 'creatorName'
    },
    {
        title: '填报时间',
        dataIndex: 'createTime'
    },
    {
        title: '状态',
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' }
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '230px',
        scopedSlots: { customRender: 'operation' }
    }
]
const searchArr = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany
    // },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },
    {
        name: '年份',
        type: 'year',
        value: 'year',
        yearsOpen: false,
        attrs: {
            valueFormat: 'YYYY'
        }
    },
    {
        name: '填报人',
        value: 'creatorName',
        type: 'input'
    },
    {
        name: '填报时间',
        type: 'dateRange',
        value: 'activityDate',
        attr: {
            rangeFormat: ['startTime', 'endTime']
        }
    }
]

import { STable } from '@/components'
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {},
            removeApi: {
                remove: delTechnicalYearlyPlan
            }, // api
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, { param: this.queryParam })

                return getPageTechnicalYearlyPlan(requestParameters).then((res) => {
                    if (res.code === '0') {
                        res.data.list.forEach((i) => {
                            i.auditStatus = status[i.auditStatus]
                        })
                        return {
                            code: 200,
                            data: res.data.list,
                            totalSize: res.data?.total,
                            currentPage: res.data?.pageNum
                        }
                    }
                })
            }
        }
    },
    methods: {
        //搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateYearlyPlan',
                query
            })
        }
    }
}
</script>


